package com.adams.action.log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

import com.adams.access.db.bean.OptLog;
import com.adams.action.view.ViewAction;
import com.adams.common.BaseAction;
import com.adams.custom.page.mgt.service.ViewParseService;
import com.adams.custom.page.util.ViewUtil;
import com.adams.log.service.OptLogService;
import com.adams.utils.Page;

/**
 * 
 * 
 * File Name : OptLogAction.java
 * 
 * @Description : 后台日志管理类
 * @author 902990封文进
 */
public class OptLogAction extends BaseAction
{

	private ViewParseService viewParseService;

	private OptLogService optLogService;

	private int menuId;

	private String gridPanelId;

	private String viewEventId;

	private String formPanelId;

	private String viewItemId;

	private String searchPanelId;

	/**
	 * 
	 * Description : 显示布局
	 * 
	 * @return String
	 * @throws Exception
	 * 
	 */
	@SuppressWarnings("unchecked")
	public String listPanel() throws Exception
	{
		// Map map = viewParseService.getParseViewByMenuId(getUserId(), menuId);
		// write(JSONObject.fromObject(map).toString());
		write(viewParseService.getParseViewJSONByMenuId(getUserId(), menuId));
		return null;
	}

	/**
	 * Description : 显示查询条字段信息
	 * 
	 * @return
	 * @throws Exception
	 * 
	 */
	public String listSearchItem() throws Exception
	{
		// Map map = viewParseService.getParseSearchItems(getUserId(), menuId,
		// searchPanelId);
		// write(JSONObject.fromObject(map).toString());
		write(viewParseService.getParseSearchItemsJSON(getUserId(), menuId,
				searchPanelId));
		return null;
	}

	/**
	 * 
	 * Description : 显示元素
	 * 
	 * @return String
	 * @throws Exception
	 * 
	 */
	public String listGridStructure() throws Exception
	{
		// Map map = viewParseService.getParseGrids(getUserId(), gridPanelId);
		// write(JSONObject.fromObject(map).toString());
		write(viewParseService.getParseGridsJSON(getUserId(), gridPanelId));
		return null;
	}

	/**
	 * 
	 * Description : 显示数据
	 * 
	 * @return String
	 * @throws Exception
	 * 
	 */
	@SuppressWarnings("unchecked")
	public String listGridData() throws Exception
	{
		if (ViewUtil.isNuLLStr(gridPanelId))
		{
			gridPanelId = request.getParameter("gridPanelId");
		}
		if (ViewUtil.isNuLLStr(searchPanelId))
		{
			searchPanelId = request.getParameter("searchPanelId");
		}
		Map inputMap = ViewAction.requestParameterMap2Map(request);
		Map map = viewParseService.getParseGridDatas(getUserId(), gridPanelId,
				searchPanelId, inputMap);
		write(JSONObject.fromObject(map).toString());
		return null;
	}
	
	/**
	 * 
	 * Description : 删除参数
	 * 
	 * @return String
	 * @throws Exception
	 * 
	 */
	@SuppressWarnings("unchecked")
	public String delete() throws Exception
	{
		List<Map> mapList = ViewAction.getDataMap(request);
		viewParseService
				.deleteDataByViewForm(getUserId(), viewEventId, mapList);

		Map result = new HashMap();
		result.put("success", true);
		result.put("msg", "删除成功!");
		write(JSONObject.fromObject(result).toString());
		return null;
	}

	// /////////////////////属性设置/////////////////////////

	public void setMenuId(int menuId)
	{
		this.menuId = menuId;
	}

	public void setViewParseService(ViewParseService viewParseService)
	{
		this.viewParseService = viewParseService;
	}

	public void setOptLogService(OptLogService optLogService)
	{
		this.optLogService = optLogService;
	}

	public void setViewEventId(String viewEventId)
	{
		this.viewEventId = viewEventId;
	}

	public void setViewItemId(String viewItemId)
	{
		this.viewItemId = viewItemId;
	}

	public void setFormPanelId(String formPanelId)
	{
		this.formPanelId = formPanelId;
	}

	public void setGridPanelId(String gridPanelId)
	{
		this.gridPanelId = gridPanelId;
	}

	public void setSearchPanelId(String searchPanelId)
	{
		this.searchPanelId = searchPanelId;
	}
}
